package com.intellagric.controller.module.trace_invest;


import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.TraceInvestType;
import com.intellagric.service.traceability.trace_invest.InvestTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/9
 * @DESC： 投入品类型信息管理
 */
@Controller
public class InvestTypeController {

    @Autowired
    private InvestTypeService investTypeService;

    /**
     * 添加投入品类型信息
     * @Param investType
     * @return ResponseMessage
     */
    @RequestMapping("/invest/type/add")
    @ResponseBody
    public ResponseMessage add(TraceInvestType investType) {
        investType.setId(UUID.randomUUID().toString().replaceAll("-",""));
        investType.setCreateDate(new Date());
        investType.setUpdateDate(new Date());
        return investTypeService.addInvestType(investType);
    }


    /**
     * 删除投入品类型信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/invest/type/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return investTypeService.deleteInvestType(id);
    }

    /**
     * 修改投入品类型信息
     * @Param investType
     * @return ResponseMessage
     */
    @RequestMapping("/invest/type/edit")
    @ResponseBody
    public ResponseMessage edit(TraceInvestType investType) {
        investType.setUpdateDate(new Date());
        return investTypeService.editInvestType(investType);
    }

    /**
     * 查询投入品类型信息
     * @return TraceInvestType
     */
    @RequestMapping("/invest/type/{id}")
    @ResponseBody
    public TraceInvestType get(@PathVariable String id) {
        return investTypeService.getInvestTypeById(id);
    }

    /**
     * 查询投入品类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/type/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return investTypeService.getInvestTypeTree();
    }
    /**
     * 查询投入品类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/type/treeByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getTree(String createBy) {
        return investTypeService.getInvestTypeTree(createBy);
    }

    /**
     * 查询投入品类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/type/tree/selectByCreateBy")
    @ResponseBody
    public List<TraceInvestType> getTreeSelect(String createBy) {
        return investTypeService.getInvestTypeTree(createBy).getData();
    }

    /**
     * 查询投入品类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/type/tree/select")
    @ResponseBody
    public List<TraceInvestType> getTreeSelect() {
        return investTypeService.getInvestTypeTree().getData();
    }

    /**
     * 查询投入品类型信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/invest/type/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return investTypeService.getInvestTypeList();
    }

}
